import { axios } from '@/util';
import { LoginRequest, QueryParams, User, Response } from '@/types';

const urls = {
  login: `auth/login`,
  logout: `auth/logout`,
  users: `user`,
  info: `auth/info`,
  refresh: `auth/refresh`,
};

export const login = async (loginRequest: LoginRequest): Promise<Response | undefined> => {
  return await axios.post(urls.login, loginRequest);
};

export const logout = async (): Promise<Response | undefined> => {
  return await axios.get(urls.logout);
};

export const refreshToken = async (): Promise<Response | undefined> => {
  return await axios.get(urls.refresh);
};

export const getUsers = async (params: QueryParams): Promise<Response | undefined> => {
  return await axios.get(urls.users, { params: params });
};

export const createUser = async (user: User): Promise<Response | undefined> => {
  return await axios.post(urls.users, user);
};

export const updateUser = async (user: User): Promise<Response | undefined> => {
  return await axios.put(urls.users, user);
};

export const getAuthInfo = async (): Promise<Response | undefined> => {
  return await axios.get(urls.info);
};
